from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.globals import ThemeType

# 数据
data = [
    ("销售部", 29.2),
    ("采购部", 22.7),
    ("工程部", 17.5),
    ("财务部", 13.6),
    ("行政部", 10.3),
    ("人力部", 6.7)
]

# 创建玫瑰饼图
pie = (
    Pie(init_opts=opts.InitOpts(bg_color='#1A1E43', theme=ThemeType.DARK))
    .add(
        "",
        data,
        rosetype='radius'  # 设置玫瑰图类型，可选 "radius" 或 "area"
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="2021年各部门人数分布",
            subtitle="公司总人数1664，销售部门人数最多451，占比29.2%",
            pos_left="left",
            title_textstyle_opts=opts.TextStyleOpts(color="#ffffff")
        ),
        legend_opts=opts.LegendOpts(is_show=False),
    )
    .set_series_opts(
        label_opts=opts.LabelOpts(formatter="{b}: {d}%")
    )
)

pie.render("pie_chart.html")
